#include "EthernetII.h"

EthernetII::EthernetII()
{}

int EthernetII::parse(Packet* pkt)
{
	if(sizeof(EthernetII_Header) >= pkt->pktLength - pkt->parsePos)
	{
		pkt->state = STATE_FAIL;
		return -1;
	}

	uint8_t* data = pkt->rawPkt + pkt->parsePos;

	EthernetII_Header* header = (EthernetII_Header*)data;

//	printf("dstMac = %02x:%02x:%02x:%02x:%02x:%02x\n", header->dstMac[0], header->dstMac[1], header->dstMac[2], header->dstMac[3], header->dstMac[4], header->dstMac[5]);
//	printf("srcMac = %02x:%02x:%02x:%02x:%02x:%02x\n", header->srcMac[0], header->srcMac[1], header->srcMac[2], header->srcMac[3], header->srcMac[4], header->srcMac[5]);

	pkt->parsePos += sizeof(EthernetII_Header);

	if(2048 == ntohs(header->type))
	{
		pkt->state = STATE_IP;
	}
	else
	{
		pkt->state = STATE_FAIL;
	}

	return 0;
}
